package com.chaoyong.higo.view;

import java.util.List;

import com.chaoyong.higo.R;
import com.chaoyong.higo.adapter.RecordDialogAdapter;
import com.chaoyong.higo.bean.GoodsRecordBean_z;
import com.chaoyong.higo.utils.V;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.GridView;
import android.widget.TextView;

/**
 * 云筹记录--显示所有云筹码的Dialog
 * 
 * @author Administrator
 *
 */
public class PurchaseRecordDialog extends Dialog {

//	private Activity mContext;
	private Context mContext;
	/** × */
	private TextView dialog_cancle_tv;
	private GridView dialog_codes_lay;
	private RecordDialogAdapter adapter;
	private List<String> codes;
	private  View contentView;

	public PurchaseRecordDialog(Context context,List<String> codes) {
		this(context, R.style.quick_option_dialog);
		this.mContext = context;
		this.codes = codes;
		initViews();
	}

	public PurchaseRecordDialog(Context context, int themeResId) {
		super(context, themeResId);
		contentView = getLayoutInflater().inflate(R.layout.dialog_purchase_record, null);
		dialog_cancle_tv = V.f(contentView, R.id.dialog_cancle_tv);
		contentView.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				PurchaseRecordDialog.this.dismiss();
			}
		});
		dialog_cancle_tv.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				PurchaseRecordDialog.this.dismiss();
			}
		});
		super.setContentView(contentView);
	}

	public PurchaseRecordDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().setGravity(Gravity.CENTER);
		WindowManager m = getWindow().getWindowManager();
		Display d = m.getDefaultDisplay();
		WindowManager.LayoutParams p = getWindow().getAttributes();
		
		Point size = new Point(); 
		d.getSize(size);
		p.height = (int) ((size.x)*1.0);
		p.width = (int)((size.y)*0.5);
//		p.height = (int) (d.getHeight() * 0.8); // 高度设置为屏幕的1.0
//		p.width = (int) (d.getWidth() * 0.6); // 宽度设置为屏幕的0.8
		
		getWindow().setAttributes(p);
	}

	private void initViews() {
		dialog_codes_lay = (GridView) findViewById(R.id.dialog_codes_lay);
		dialog_codes_lay.setSelector(new ColorDrawable(Color.TRANSPARENT));
		adapter = new RecordDialogAdapter(mContext,codes);
		dialog_codes_lay.setAdapter(adapter);
	}

}
